;(function($){
		$.fn.cgCalendar=function(o){
		/*
			disabledDates，selectedDates
			指定的日期格式为"yyyy-mm-dd",如日期格式不正确则会以当前时间为默认日期
			timeRange
			指定的日期格式为"hh:MM:ss"
			dateRange，startDate
			指定的日期格式为"yyyy-mm-dd hh:MM:ss",如日期格式不正确则会以当前时间为默认日期
			disabledMonths,disabledWeeks,startWeek中的均以0为起始位置
		*/
		var o=$.extend(true,{
			format:"yyyy-mm-dd hh:MM:ss",//yyyy：年份 mm：月份 dd:天 hh：时间 MM ss：秒钟
			shortWeeks:["日","一","二","三","四","五","六"],/*["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],*/
			weeks:["星期天","星期一","星期二","星期三","星期四","星期五","星期六"],
			months:["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],/*["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],*/			
			shortMonths:["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
			timeName:["时","分","秒"],
			buttons:["清空","今天","确定"],
			startWeek:0,//一个星期，开头的星期数
			disabledDates:null,
			disabledDays:null,
			disabledWeeks:null,
			disabledMonths:null,
			disabledYears:null,
			disabledTimes:null,
			disabledHours:null,
			disabledMinutes:null,
			disabledSeconds:null,
			selectedDates:null,
			showTime:true,//是否显示时间
			showTimeSelect:true,//是否显示时间选择器
			showTolls:true,//是否显示工具栏
			showClear:true,//是否显示清空按钮
			showToday:true,//是否显示今天按钮
			showOk:true,//是否显示确定按钮			
			startDate:null,//可传递指定的日期格式或者是日期，如果日期格式不正确则当前时间为默认的日期
			dateRange:null,//日期选择区间，可为date类型或指定格式日期字符串
			timeRange:null,//时间选择区间，可为date类型或者为hh:MM:ss格式的时间字符串
			validateDate:null,//验证日期，可根据日期进行判断
			beforeSelect:null,//点击日期，today按钮，ok按钮都会触发该事件
			beforeClick:null,//日期单击之前的事件，return false;可以阻止日期填充input
			click:null,//单击日期时触发click事件
			mouseover:null,
			mouseout:null,
			dblclick:null,
			clearHandler:null,//清空按钮事件
			todayHandler:null,//今天按钮事件
			okHandler:null,//确定按钮事件			
			eventName:null,//自定义事件，为jquery的某一个事件
			event:null,//自定义事件执行函数
			speed:100,//日历显示或隐藏所需时间
			width:null,//宽度与高度，建议高度不要定义
			height:null,
			url:"",//日期的链接地址
			language:"zn"//日历插件语言，为null时，可自定义语言
		},o||{});
		var tolls={
			stringToDate:function(str,format){
				var today=new Date();
				var regStr="^"+format+"$",reg,year=today.getFullYear(),month=today.getMonth()+1,day=today.getDate(),hour=0,minute=0,second=0,date;
				try{
					var m;
					if(format.indexOf("yyyy")!=-1){						
						reg= new RegExp(privateMethods.getReg(regStr,"yyyy"));
						m=str.match(reg);
						if(m&&m[1]){
							year=m[1];
						}
					}					
					if(format.indexOf("mm")!=-1){
						reg= new RegExp(privateMethods.getReg(regStr,"mm"));
						m=str.match(reg);
						if(m&&m[1]){
							month=m[1];
						}
					}
					if(format.indexOf("dd")!=-1){
						reg= new RegExp(privateMethods.getReg(regStr,"dd"));
						m=str.match(reg);
						if(m&&m[1]){
							day=m[1];
						}
					}
					if(format.indexOf("hh")!=-1){
						reg= new RegExp(privateMethods.getReg(regStr,"hh"));
						m=str.match(reg);
						if(m&&m[1]){
							hour=m[1];
						}
					}
					if(format.indexOf("MM")!=-1){
						reg= new RegExp(privateMethods.getReg(regStr,"MM"));
						m=str.match(reg);
						if(m&&m[1]){
							minute=m[1];
						}
					}
					if(format.indexOf("ss")!=-1){
						reg= new RegExp(privateMethods.getReg(regStr,"ss"));
						m=str.match(reg);
						if(m&&m[1]){
							second=m[1];
						}
					}
					date=new Date(year,month-1,day,hour,minute,second,0);
				}catch(e){
					return new Date();
				}
				return date;
			},
			dateToString:function(date,format){
				var str="";
				var convert=function(date,format){
					format=format.replace("yyyy",date.getFullYear());
					format=format.replace("mm",(date.getMonth()+1)>=10?date.getMonth()+1:"0"+(date.getMonth()+1));
					format=format.replace("dd",date.getDate()>=10?date.getDate():"0"+date.getDate());
					format=format.replace("hh",date.getHours()>=10?date.getHours():"0"+date.getHours());
					format=format.replace("MM",date.getMinutes()>=10?date.getMinutes():"0"+date.getMinutes());
					format=format.replace("ss",date.getSeconds()>=10?date.getSeconds():"0"+date.getSeconds());
					format=format.replace("w",o.weeks[date.getDay()]);
					return format;
				};
				try{
					str=convert(date,format);
				}catch(e){
					str=convert(new Date(),format);
				}
				return str;
			},
			getRealDate:function(date,format){
				if(typeof date == "string"){
					date=tolls.stringToDate(date,format);
				}else if(!date){
					return new Date();
				}
				return date;
			},			
			show:function(t){
				if(arguments.length==0){
					t=this.doms.datepicker;					
				}
				t.fadeIn(o.speed);
			},
			hide:function(t){
				if(arguments.length==0){
					t=this.doms.datepicker;
				}
				t.fadeOut(o.speed);
			},
			isDisabledDate:function(date,obj,f){
				var d=date,dateRange;
				if(typeof f !="undefined" && f){
					if(this.doms){
						var disabledDates=privateMethods.unique(privateMethods.merge(this.doms.disabledDates||[],o.disabledDates||[])),
						disabledDays=privateMethods.unique(privateMethods.merge(this.doms.disabledDays||[],o.disabledDays||[])),
						disabledWeeks=privateMethods.unique(privateMethods.merge(this.doms.disabledWeeks||[],o.disabledWeeks||[])),
						disabledYears=privateMethods.unique(privateMethods.merge(this.doms.disabledYears||[],o.disabledYears||[])),
						disabledMonths=privateMethods.unique(privateMethods.merge(this.doms.disabledMonths||[],o.disabledMonths||[]));
					}else{
						var disabledDates=o.disabledDates,
						disabledDays=o.disabledDays,
						disabledWeeks=o.disabledWeeks,
						disabledYears=o.disabledYears,
						disabledMonths=o.disabledMonths;
					}
					if(disabledDates){
						var str=tolls.dateToString(date,"yyyy-mm-dd");
						for(var i=0;i<disabledDates.length;i++){
							if(str==disabledDates[i]){
								return true;
							}
						}
					}
					if(disabledDays){
						var d=date.getDate();
						for(var i=0;i<disabledDays.length;i++){
							if(d==disabledDays[i]){
								return true;
							}
						}
					}
					if(disabledWeeks){
						var w=date.getDay();
						for(var i=0;i<disabledWeeks.length;i++){
							if(w==disabledWeeks[i]){
								return true;
							}
						}
					}
					if(disabledYears){
						var y=date.getFullYear();
						for(var i=0;i<disabledYears.length;i++){						
							if(y==disabledYears[i]){
								return true;
							}
						}
					}
					if(disabledMonths){
						var m=date.getMonth();
						for(var i=0;i<disabledMonths.length;i++){
							if(m==disabledMonths[i]){
								return true;
							}
						}
					}
					dateRange=obj.dateRange;
					d=new Date(date.getFullYear(),date.getMonth(),date.getDate(),0,0,0,0);
				}else{				
					dateRange=o.dateRange;
					if(!o.showTime){
						d=new Date(date.getFullYear(),date.getMonth(),date.getDate(),0,0,0,0);
					}
				}
				if(!dateRange||!dateRange.min&&!dateRange.max) return false;
				if(dateRange.max&&dateRange.min&&d<=dateRange.max&&d>=dateRange.min||!dateRange.min&&dateRange.max&&d<=dateRange.max||!dateRange.max&&dateRange.min&&d>=dateRange.min){					
					return false;
				}else{
					return true;
				}
				return false;
			},
			isDisabledTime:function(arg,m,s){
				if(!o.showTime) return false;
				if(this.doms){
					var disabledHours=privateMethods.unique(privateMethods.merge(this.doms.disabledHours||[],o.disabledHours||[])),
					disabledMinutes=privateMethods.unique(privateMethods.merge(this.doms.disabledMinutes||[],o.disabledMinutes||[])),
					disabledSeconds=privateMethods.unique(privateMethods.merge(this.doms.disabledSeconds||[],o.disabledSeconds||[])),
					disabledTimes=privateMethods.unique(privateMethods.merge(this.doms.disabledTimes||[],o.disabledTimes||[]));
				}else{
					var disabledHours=o.disabledHours,
					disabledMinutes=o.disabledMinutes,
					disabledSeconds=o.disabledSeconds,
					disabledTimes=o.disabledTimes;
				}
				
				if(arguments.length==1){
					try{
						var h=arg.getHours();
						m=arg.getMinutes();
						s=arg.getSeconds();
						h=h>9?h:("0"+h);
						m=m>9?m:("0"+m);
						s=s>9?s:("0"+s);
					}catch(e){
						return undefined;
					}
				}else{
					var h=arg;
					if(h.length==1){h="0"+h;}
					if(m.length==1){m="0"+m;}
					if(s.length==1){s="0"+s;}
				}				
				if(disabledTimes){
					var str=(h)+":"+(m)+":"+(s);
					for(var i=0;i<disabledTimes.length;i++){
						if(str==disabledTimes[i]){
							return true;
						}
					}
				}				
				if(disabledHours){					
					for(var i=0;i<disabledHours.length;i++){
						if(h==disabledHours[i]){
							return true;
						}
					}
				}
				if(disabledMinutes){
					for(var i=0;i<disabledMinutes.length;i++){
						if(m==disabledMinutes[i]){
							return true;
						}
					}
				}
				if(disabledSeconds){
					for(var i=0;i<disabledSeconds.length;i++){						
						if(s==disabledSeconds[i]){
							return true;
						}
					}
				}
				if(!o.timeRange||!o.timeRange.min&&!o.timeRange.max) return false;
				var time=new Date(1970,0,1,h,m,s,0);				
				if(o.timeRange.min&&o.timeRange.max&&time>=o.timeRange.min&&time<=o.timeRange.max||!o.timeRange.max&&o.timeRange.min&&time>=o.timeRange.min||!o.timeRange.min&&o.timeRange.max&&time<=o.timeRange.max){
					return false;
				}else{
					return true;
				}
				return false;
			},
			getDate:function($this,obj){				
				if(arguments.length==1){
					obj=this.doms;
				}
				var date=new Date($this.attr("year"),$this.attr("month"),$this.attr("day"),obj.hour.val()||0,obj.minute.val()||0,obj.second.val()||0,0);
				return date;
			},
			nextMonth:function(date){
				date.setMonth(date.getMonth()+1);
				return date;
			},
			prevMonth:function(date){				
				date.setMonth(date.getMonth()-1);
				return date;
			},
			nextYear:function(date){				
				date.setYear(date.getFullYear()+1);
				return date;
			},
			prevYear:function(date){
				date.setYear(date.getFullYear()-1);
				return date;
			},
			setDateRange:function(range){
				o.dateRange=range;
				privateMethods.initDateRange(this.doms);
			},
			setTimeRange:function(range){
				o.timeRange=range;
				privateMethods.initTimeRange();
			},
			getDoms:function(){
				return this.doms;
			},
			refresh:function(date){
				var d=date;
				if(arguments.length==0){
					privateMethods.setMonthByDate(this.doms.currentDate,this.doms);
					d=this.doms.currentDate;
				}else{
					privateMethods.setMonthByDate(date,this.doms);
					this.doms.currentDate=new Date(date);
				}
				if(o.showTime&&o.showTimeSelect){
					this.doms.hoursBox.children("table").html(privateMethods.getHMSHtml("h",this.doms));
					this.doms.minutesBox.children("table").html(privateMethods.getHMSHtml("m",this.doms));
					this.doms.secondsBox.children("table").html(privateMethods.getHMSHtml("s",this.doms));
				}
				if(o.showTime&&arguments.length>=1){
					var h=d.getHours(),m=d.getMinutes(),s=d.getSeconds();
					this.doms.hour.val(h>9?h:("0"+h));
					this.doms.minute.val(m>9?m:("0"+m));
					this.doms.second.val(s>9?s:("0"+s));
				}
			},
			destory:function(){
				if(this.doms.isInput){this.doms.$this.unbind("click foucsin");}
				this.doms.datepicker.remove();
			}
		};
		var privateMethods={
			unique:function(data){
				data = data || [];
				var a = {};
				for (var i = 0; i < data.length; i++) {
					var v = data[i];
					if (typeof(a[v]) == 'undefined') {
						a[v] = 1;
					}
				};
				data.length = 0;
				for (var i in a) {
					data[data.length] = i;
				}
				return data;
			},
			merge:function(ar1){
				var l=arguments.length,data=new Array();
				for(var i=0;i<l;i++){
					var len=arguments[i].length;
					for(var j=0;j<len;j++){
						data.push(arguments[i][j]);
					}
				}
				return data;
			},
			getReg:function(regStr,str){
				regStr=regStr.replace(str,"("+str+")");
				regStr=regStr.replace("yyyy","\\d{4}");
				regStr=regStr.replace("mm","\\d{2}");
				regStr=regStr.replace("dd","\\d{2}");
				regStr=regStr.replace("hh","\\d{2}");
				regStr=regStr.replace("MM","\\d{2}");
				regStr=regStr.replace("ss","\\d{2}");
				return regStr;
			},
			setMonthByDate:function(date,obj){
				var year=date.getFullYear(),month=date.getMonth();
				obj.daysBox.html(privateMethods.getDaysHtml(year,date.getMonth(),obj));
				obj.month.html(o.months[month]).attr("month",month);
				obj.year.html(year).attr("year",year);
				obj.ableDays=$(".days td:not('.unselected-day'):not('.un-day') a",obj.datepicker[0]);
				obj.unselectedDays=$(".days .unselected-day a",obj.datepicker[0]);
				obj.unDays=$(".days .un-day a",obj.datepicker[0]);
				obj.days=$(".days a",obj.datepicker[0]);
			},
			selectDate:function(date,obj,f){
				if(obj.isInput){
					var dateStr=tolls.dateToString(date,o.format);
					obj.$this.val(dateStr);
					obj.$this.data("date",date);
					tolls.hide(obj.datepicker);
				}
				//由于setMonthByDate耗时较多，所以当下列三个事件不为空时才执行
				//if($.isFunction(o.beforeSelect)||$.isFunction(o.beforeClick)||$.isFunction(o.click)){
					privateMethods.setMonthByDate(date,obj);
				//}else{
				//	obj.ableDays.filter("[day='"+date.getDate()+"']").parent().addClass("selected-day");
				//}
				if(typeof f != "undefined" && f){
					var h=date.getHours(),m=date.getMinutes(),s=date.getSeconds();
					obj.hour.val(h>9?h:("0"+h));
					obj.minute.val(m>9?m:("0"+m));
					obj.second.val(s>9?s:("0"+s));
				}
			},
			getDays:function(year,month){
				var d=new Date(year, month + 1, 0);
				return d.getDate();
			},
			getDaysHtml:function(year,month,obj){
				var html="",
				days=privateMethods.getDays(year,month),
				html="<tr>"+privateMethods.getPreDaysHtml(year,month),
				selectedDates=new Array(),len,
				today=tolls.dateToString(obj.today,"yyyy-mm-dd");				
				selectedDates=privateMethods.unique(privateMethods.merge(obj.clickDates,obj.selectedDates||[],o.selectedDates));
				len=selectedDates.length;
				var getClass=function(currentDay){
					var dayHtml=$("<td></td>");
					if(tolls.isDisabledDate(currentDay,obj,1)){
						dayHtml.addClass("unselected-day");
					}
					if(!dayHtml.hasClass("unselected-day")){
						var str=tolls.dateToString(currentDay,"yyyy-mm-dd");
						for(var i=0;i<len;i++){
							if(str==selectedDates[i]){
								dayHtml.addClass("selected-day");
								break;
							}
						}
					}
					if(str==today){
						dayHtml.addClass("today");
					}
					if(dayHtml.attr("class")){
						return 'class="'+dayHtml.attr("class")+'"';
					}
					return "";
				};
				for(var i=1,j=privateMethods.getPreDays(year,month);i<=days;i++,j++){
					if(!(j%7)&&j!=0){
						html+="</tr><tr>";
					}
					//jquery会自动检测标签中的元素是否符合要求，如不符合要求则会去掉不符合要求的标签
					var currentDay=new Date(year,month,i),
					s=tolls.dateToString(currentDay,o.format),
					tdHtml='<tr><td '+getClass(currentDay)+'><a href="'+(o.url||"")+'" year="'+year+'" month="'+month+'" day="'+i+'">'+i+'</a></td></tr>',
					$td=$(tdHtml);
					if($.isFunction(o.validateDate)){
						o.validateDate.call(this,s,currentDay,$("td a",$td),obj);
					}
					html+=$td.html();
				}
				html+=privateMethods.getNextDaysHtml(year,month)+"</tr>";
				return html;
			},
			getPreDays:function(year,month){
				var date=new Date(year,month,1);
				var week=(date.getDay()+7-o.startWeek)%7,n;
				n=week;
				return n;
			},
			getPreDaysHtml:function(year,month){
				var n=privateMethods.getPreDays(year,month),html="";
				var days=privateMethods.getDays(year,month-1);
				var date=new Date(year,month-1,days);
				var y=date.getFullYear(),m=date.getMonth();
				for(var i=days-n+1;i<=days;i++){
					html+='<td class="un-day">'+'<a href="'+(o.url||"")+'" year="'+y+'" month="'+m+'" day="'+i+'">'+i+'</a>'+'</td>';
				}
				return html;
			},
			getNextDays:function(year,month){
				var date=new Date(year,month,privateMethods.getDays(year,month));
				var week=(date.getDay()+7-o.startWeek)%7,n;
				n=7-week-1;
				return n;
			},
			getNextDaysHtml:function(year,month){
				var n=privateMethods.getNextDays(year,month),html="";
				var date=new Date(year,month+1,1);
				var y=date.getFullYear(),m=date.getMonth();
				for(var i=1;i<=n;i++){
					html+='<td class="un-day">'+'<a href="'+(o.url||"")+'" year="'+y+'" month="'+m+'" day="'+i+'">'+i+'</a>'+'</td>';
				}
				return html;
			},
			getWeeksHtml:function(){
				var html='<thead  class="weeks"><tr>';
				for(var i=o.startWeek,j=0;j<7;i=(i+1)%7,j++){
					html+='<th>'+o.shortWeeks[i]+'</th>';
				}
				html+='</tr></thead>';
				return html;
			},
			getYearsHtml:function(year,type,obj){
				var html="<tr>";
				for(year=(type=="+"?year:year-19),j=0;j<20;j++,year++){
					if(!(j%4)&&j!=0){
						html+="</tr><tr>";
					}
					html+='<td year="'+year+'">'+year+'</td>';
				}
				obj.years=$("td:not('.un-year')",$(html+"</tr>"));
				return html+"</tr>";
			},
			getMonthsHtml:function(){
				var html="<tr>";
				for(var i=0;i<12;i++){
					if(!(i%2)&&i!=0){
						html+="</tr><tr>";
					}
					html+='<td month="'+i+'">'+o.months[i]+'</td>';
				}
				return html+"</tr>";
			},
			getHMSHtml:function(t,obj){
				var html="<tr>",ary,atr="hour",max=59,imax=63;				
				if(t=="h"){
					if(obj){
						ary=privateMethods.unique(privateMethods.merge(obj.disabledHours||[],o.disabledHours||[]));
					}else{
						ary=o.disabledHours;
					}
					max=23;
					imax=28;
				}else if(t=="m"){
					if(obj){
						ary=privateMethods.unique(privateMethods.merge(obj.disabledMinutes||[],o.disabledMinutes||[]));
					}else{
						ary=o.disabledMinutes;
					}
					atr="minute";
				}else{
					if(obj){
						ary=privateMethods.unique(privateMethods.merge(obj.disabledSeconds||[],o.disabledSeconds||[]));
					}else{
						ary=o.disabledSeconds;
					}					
					atr="second";
				}
				var checkTime=function(j,atr){
					var min,max,html;
					if(o.timeRange.min) min=o.timeRange.min.getHours();
					if(o.timeRange.max) max=o.timeRange.max.getHours();
					if(min&&max&&j>=min&&j<=max||!max&&min&&j>=min||!min&&max&&j<=max){
						html='<td '+atr+'="'+j+'">'+j+'</td>';
					}else{
						html='<td class="unselected-time" '+atr+'="'+j+'">'+j+'</td>';
					}					
					return html;
				};
				for(var i=0,j=0;i<imax;i++){
					if(!(i%7)&&i!=0){
						html+="</tr><tr>";
					}
					if(j>max){
						if(i==imax-1){
							html+='<td class="un-time" title="close">x</td>';
						}else{
							html+='<td class="un-time" title="close"></td>';
						}
						continue;
					}else{
						var k=0,g=j;
						j=j>9?j:"0"+j;
						if(ary){
							var len=ary.length;
							for(k=0;k<len;k++){
								if(g==ary[k]){
									html+='<td class="unselected-time" '+atr+'="'+j+'">'+j+'</td>';
									break;
								}
							}
							if(ary&&k==len){
								if(t=="h"&&o.timeRange){
									html+=checkTime(j,atr);
								}else{
									html+='<td '+atr+'="'+j+'">'+j+'</td>';
								}
							}
						}else{
							if(t=="h"&&o.timeRange){
								html+=checkTime(j,atr);
							}else{
								html+='<td '+atr+'="'+j+'">'+j+'</td>';
							}
						}
						j++;						
					}
				}
				return html+"</tr>";
			},
			createHtml:function(date,obj){				
				var year=date.getFullYear(),month=date.getMonth(),hour=date.getHours(),minute=date.getMinutes(),second=date.getSeconds();
				hour=hour>9?hour:("0"+hour);
				minute=minute>9?minute:("0"+minute);
				second=second>9?second:("0"+second);				
				var navHtml='<div class="nav"><div class="month-nav"><span class="button prev">&#171;</span><span class="month-name"></span><span class="button next">&#187;</span>'
				+'</div><div class="year-nav"><span class="button prev">&#171;</span><span class="year-name"></span><span class="button next">&#187;</span></div></div>';
				var timeHtml='<div class="time"><span class="hour">'+o.timeName[0]+' : <input type="text" id="hour" maxlength="2" value="'+hour+'"/></span> <span class="minute">'+o.timeName[1]+' : '
				+'<input type="text" id="minute" maxlength="2" value="'+minute+'"/></span> <span class="second">'+o.timeName[2]+' : <input type="text" id="second" maxlength="2" value="'+second+'"/></span></div>';
				var tollbarsHtml='<div class="tollbars">';
				if(o.showOk) tollbarsHtml+='<input type="button" value="'+o.buttons[2]+'" id="okBtn"/>';
				if(o.showToday) tollbarsHtml+='<input type="button" value="'+o.buttons[1]+'" id="todayBtn"/>';
				if(o.showClear) tollbarsHtml+='<input type="button" value="'+o.buttons[0]+'" id="clearBtn"/>';				
				tollbarsHtml+='</div>';
				var yearHtml='<div class="year" id="year"><table></table><div class="year-tollbars"><span class="button prev">&#171;</span><span class="year-name"></span><span class="button next">&#187;</span></div></div>';
				var monthHtml='<div class="month" id="month"><table></table></div>';
				var html='<div class="datepicker" id="datepicker">';
				html+=navHtml+'<table id="days">'+privateMethods.getWeeksHtml()+'<tbody class="days"></tbody></table>';								
				if(o.showTime){
					html+=timeHtml;
				}
				if(o.showTolls){
					html+=tollbarsHtml;
				}
				if(o.showTime&&o.showTimeSelect){
					html+='<div id="hour-select" class="time-select"><table>'+privateMethods.getHMSHtml("h",obj)+'</table></div>';
					html+='<div id="minute-select" class="time-select"><table>'+privateMethods.getHMSHtml("m")+'</table></div>';
					html+='<div id="second-select" class="time-select"><table>'+privateMethods.getHMSHtml("s")+'</table></div>';
				}
				
				html=html+yearHtml+monthHtml;
				html+="</div>";
				return html;
			},
			_hideIfClickOutside:function(event){
				var obj=event.data.datepickerInput,target=$(event.target);
				//皆可实现
				if(event.target!= obj[0] && !privateMethods._checkPosition(event,event.data.datepicker)){
				//if(event.target!= obj[0] && (target.parent(".datepicker").length<1 && target.parentsUntil(".datepicker").parent(".datepicker").length<1 && !target.hasClass("datepicker"))){
					tolls.hide(event.data.datepicker);
					//$(document).unbind("click",privateMethods._hideIfClickOutside);
				}
			},
			_checkPosition:function(event,obj){
				var offset = obj.offset();
				offset.right = offset.left + obj.outerWidth(true);
				offset.bottom = offset.top + obj.outerHeight(true);
				return event.pageY < offset.bottom &&
					event.pageY > offset.top &&
					event.pageX < offset.right &&
					event.pageX > offset.left;
			},
			setPosition:function($this,input){
				$this.css({"position":"absolute","top":input.offset().top+input.outerHeight(true),"left":input.offset().left});
			},
			setLanguage:function(){
				switch(o.language) {
					case "en":
						o.shortWeeks=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
						o.weeks=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
						o.months=["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
						o.shortMonths=["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
						o.timeName=["hour","minute","second"];
						o.buttons=["clear","today","ok"];
						break;
					defualt:
						break;
				}
			},
			initDateRange:function(obj){
				if(o.dateRange.min){
					o.dateRange.min=tolls.getRealDate(o.dateRange.min,"yyyy-mm-dd hh:MM:ss");
					var d=new Date(o.dateRange.min.getFullYear(),o.dateRange.min.getMonth(),o.dateRange.min.getDate(),0,0,0,0);
					if(!o.showTime){o.dateRange.min=d;}
					obj.dateRange.min=d;
				}else{
					obj.dateRange.min=null;
				}
				if(o.dateRange.max){
					o.dateRange.max=tolls.getRealDate(o.dateRange.max,"yyyy-mm-dd hh:MM:ss");
					var d=new Date(o.dateRange.max.getFullYear(),o.dateRange.max.getMonth(),o.dateRange.max.getDate(),0,0,0,0);
					if(!o.showTime){o.dateRange.max=d}
					obj.dateRange.max=d;
				}else{
					obj.dateRange.max=null;
				}	
			},
			initTimeRange:function(){
				if(o.timeRange.min){
					o.timeRange.min=tolls.getRealDate(o.timeRange.min,"hh:MM:ss");
					o.timeRange.min=new Date(1970,0,1,o.timeRange.min.getHours(),o.timeRange.min.getMinutes(),o.timeRange.min.getSeconds(),0);
				}
				if(o.timeRange.max){
					o.timeRange.max=tolls.getRealDate(o.timeRange.max,"hh:MM:ss");
					o.timeRange.max=new Date(1970,"0",1,o.timeRange.max.getHours(),o.timeRange.max.getMinutes(),o.timeRange.max.getSeconds(),0);
				}
			},
			checkNum:function(e){
				var max=59;
				if(e.data){
					max=e.data.max;
				}
				if(/^[\d]{0,2}$/.test($(this).val())){
					if($(this).val()>max){
						$(this).val(max);
						return false;
					}
					return true;
				}
				$(this).val("00");
				return false;
			},
			checkCode:function(e){
				var code=e.keyCode;
				if(code>=48&&code<=57||code>=96&&code<=105||code==8||code==46||code==9){						
					return true;
				}
				return false;
			}
		};
		var calendars=new Array();
		$(this).each(function(index){
			var $this=$(this),container,obj={},$datepicker,flag=true;
			var resetData=function(){
				obj.currentDate=o.startDate;
				obj.isInput=false;
				if($this[0].tagName=="INPUT") obj.isInput=true;
				obj.clickDates=new Array();
				obj.dateRange={};
				obj.dateRange.min=null;
				obj.dateRange.max=null;
				obj.timeRange={};
				obj.timeRange.min=null;
				obj.timeRange.max=null;
				obj.selectedDates=new Array();
				o.selectedDates=o.selectedDates||[];
				if(o.dateRange){
					privateMethods.initDateRange(obj);
				}
				if(o.timeRange){
					privateMethods.initTimeRange();
				}
				if(o.startWeek<0||o.startWeek>6){
					o.startWeek=0;
				}else{
					o.startWeek=parseInt(o.startWeek);
				}
				privateMethods.setLanguage();
			};
			var init=function(){
				resetData();
				if(obj.isInput){
					if($this.val()){
						obj.currentDate=tolls.getRealDate($this.val(),o.format);
					}else{
						obj.currentDate=tolls.getRealDate(obj.currentDate,o.format);
					}
					obj.clickDates.push(tolls.dateToString(obj.currentDate,"yyyy-mm-dd"));
					$datepicker=$(privateMethods.createHtml(obj.currentDate,obj));
					container="body";
					$this.unbind("click foucsin").bind("click foucsin",function(e){
						if(flag){
							$datepicker.hide().appendTo(container);
							privateMethods.setPosition($datepicker,$this);
							tolls.show($datepicker);
							$(document).click({datepickerInput:$this,datepicker:$datepicker},privateMethods._hideIfClickOutside);
							flag=false;
						}else{
							tolls.show($datepicker);
						}
					});
				}else{
					obj.currentDate=tolls.getRealDate(obj.currentDate,o.format);
					obj.clickDates.push(tolls.dateToString(obj.currentDate,"yyyy-mm-dd"));
					$datepicker=$(privateMethods.createHtml(obj.currentDate,obj));
					container=$this;
					$datepicker.appendTo(container);
				}				
				$datepicker.css({"width":o.width,"height":o.height});
				if(!o.showTimeSelect) obj.hour=$(".time span",$datepicker).css("cursor","default");
				obj.$this=$this;
				obj.today=new Date();
				obj.datepicker=$datepicker;
				obj.month=$(".month-nav .month-name",$datepicker);
				obj.prevMonth=$(".month-nav .prev",$datepicker);
				obj.nextMonth=$(".month-nav .next",$datepicker);
				obj.year=$(".year-nav .year-name",$datepicker);
				obj.prevYear=$(".year-nav .prev",$datepicker);
				obj.nextYear=$(".year-nav .next",$datepicker);
				obj.daysBox=$("#days tbody",$datepicker);
				obj.clearBtn=$("#clearBtn",$datepicker);
				obj.todayBtn=$("#todayBtn",$datepicker);
				obj.okBtn=$("#okBtn",$datepicker);
				obj.hour=$(".time #hour",$datepicker);
				obj.minute=$(".time #minute",$datepicker);
				obj.second=$(".time #second",$datepicker);
				obj.yearBox=$("#year",$datepicker);
				obj.nextYears=$(".year-tollbars .next",obj.yearBox);
				obj.preYears=$(".year-tollbars .prev",obj.yearBox);
				obj.currentYear=$(".year-tollbars .year-name",obj.yearBox);
				obj.years=$("table td:not('.un-year')",obj.yearBox[0]);
				obj.monthBox=$("#month",$datepicker);
				obj.months=$("table td:not('.un-month')",obj.monthBox[0]);
				obj.hoursBox=$("#hour-select",$datepicker);
				obj.hours=$("#hour-select td:not(.un-time):not(.unselected-time)",$datepicker[0]);
				obj.unHours=$("#hour-select .un-time",$datepicker[0]);
				obj.minutesBox=$("#minute-select",$datepicker);
				obj.minutes=$("#minute-select td:not(.un-time):not(.unselected-time)",$datepicker[0]);
				obj.unMinutes=$("#minute-select .un-time",$datepicker[0]);
				obj.secondsBox=$("#second-select",$datepicker);
				obj.seconds=$("#second-select td:not(.un-time):not(.unselected-time)",$datepicker[0]);
				obj.unSeconds=$("#second-select .un-time",$datepicker[0]);
				/*live事件必须使用如下jquery对象选择器的方法*/
				obj.ableDays=$(".days td:not('.unselected-day'):not('.un-day') a",$datepicker[0]);
				obj.unselectedDays=$(".days .unselected-day a",$datepicker[0]);
				obj.unDays=$(".days .un-day a",$datepicker[0]);
				obj.days=$(".days a",$datepicker[0]);
				if(!o.showTimeSelect){
					obj.hour.keydown(privateMethods.checkCode).keyup({max:23},privateMethods.checkNum);
					obj.minute.keydown(privateMethods.checkCode).keyup(privateMethods.checkNum);
					obj.second.keydown(privateMethods.checkCode).keyup(privateMethods.checkNum);
				}
				privateMethods.setMonthByDate(obj.currentDate,obj);
				bindEvent();
			};
			var bindEvent=function(){
				var daysBox=$("#days",$datepicker),
				tollbars=$(".tollbars",$datepicker),
				timeBox=$(".time",$datepicker);
				var hideCalendarPanel=function(){
					daysBox.hide();
					tollbars.hide();
					timeBox.hide();
				};
				var showCalendarPanel=function(){
					daysBox.fadeIn(o.speed);
					tollbars.fadeIn(o.speed);
					timeBox.fadeIn(o.speed);
				};
				var hideTimePanel=function(){
					obj.hoursBox.hide();
					obj.minutesBox.hide();
					obj.secondsBox.hide();
				};
				var yearFlag=true,monthFlag=true;
				obj.year.click(function(){
					hideTimePanel();
					if(obj.yearBox.is(":visible")){
						obj.yearBox.hide();
						showCalendarPanel();
					}else{
						hideCalendarPanel();
						obj.monthBox.hide();
						if(yearFlag){
							var y=obj.today.getFullYear();
							obj.currentYear.html(y).attr("year",y);
							$("table",obj.yearBox).html(privateMethods.getYearsHtml(parseInt(obj.year.html()),"+",obj));							
							yearFlag=false;
						}
						obj.yearBox.fadeIn(o.speed);
					}
					return false;
				});
				obj.nextYears.click(function(){
					$("table",obj.yearBox).html(privateMethods.getYearsHtml(parseInt(obj.years.eq(obj.years.length-1).html())+1,"+",obj));
				});
				obj.preYears.click(function(){
					$("table",obj.yearBox).html(privateMethods.getYearsHtml(parseInt(obj.years.eq(0).html())-1,"-",obj));
				});
				obj.years.live("click",function(){					
					var year=$(this).attr("year");
					obj.currentDate.setYear(year);
					privateMethods.setMonthByDate(obj.currentDate,obj);
					obj.yearBox.hide();
					showCalendarPanel();
				});
				obj.currentYear.bind("click",function(){
					var year=$(this).attr("year");
					obj.currentDate.setYear(year);
					privateMethods.setMonthByDate(obj.currentDate,obj);
					obj.yearBox.hide();
					showCalendarPanel();
				});
				obj.month.click(function(){
					hideTimePanel();
					if(obj.monthBox.is(":visible")){
						obj.monthBox.hide();
						showCalendarPanel();
					}else{
						hideCalendarPanel();
						obj.yearBox.hide();
						if(monthFlag){
							$("table",obj.monthBox).html(privateMethods.getMonthsHtml());
							obj.months=$("table td:not('.un-month')",obj.monthBox[0]);
							monthFlag=false;
						}
						obj.monthBox.fadeIn(o.speed);
					}
					return false;
				});
				obj.months.live("click",function(){
					var month=$(this).attr("month");
					obj.currentDate.setMonth(month);
					privateMethods.setMonthByDate(obj.currentDate,obj);
					obj.monthBox.hide();
					showCalendarPanel();
				});
				var timeEvent=function(){
					$(".time .hour",$datepicker).click(function(){
						hideCalendarPanel();
						obj.hoursBox.fadeIn(o.speed);
						return false;
					});
					$(".time .minute",$datepicker).click(function(){
						hideCalendarPanel();
						obj.minutesBox.fadeIn(o.speed);
						return false;
					});
					$(".time .second",$datepicker).click(function(){
						hideCalendarPanel();
						obj.secondsBox.fadeIn(o.speed);
						return false;
					});
					obj.hours.live("click",function(){
						obj.hour.val($(this).attr("hour"));
						obj.hoursBox.hide();
						showCalendarPanel();
					});
					obj.minutes.live("click",function(){
						//此判断不行，会出现不能选择时间的问题
						//if(!tolls.isDisabledTime(obj.hour.val(),$(this).attr("minute"),obj.second.val())){
							obj.minute.val($(this).attr("minute"));
							obj.minutesBox.hide();
							showCalendarPanel();
						//}
					});
					obj.seconds.live("click",function(){						
						if(!tolls.isDisabledTime(obj.hour.val(),obj.minute.val(),$(this).attr("second"))){
							obj.second.val($(this).attr("second"));
							obj.secondsBox.hide();
							showCalendarPanel();
						}
					});
					obj.unHours.live("click",function(){						
						obj.hoursBox.hide();
						showCalendarPanel();
					});
					obj.unMinutes.live("click",function(){						
						obj.minutesBox.hide();
						showCalendarPanel();
					});
					obj.unSeconds.live("click",function(){						
						obj.secondsBox.hide();
						showCalendarPanel();
					});
				};
				if(o.showTimeSelect) timeEvent();
				obj.prevMonth.click(function(){				
					var date=tolls.prevMonth(obj.currentDate);
					privateMethods.setMonthByDate(date,obj);
				});
				obj.nextMonth.click(function(){
					var date=tolls.nextMonth(obj.currentDate);
					privateMethods.setMonthByDate(date,obj);
				});
				obj.prevYear.click(function(){
					var date=tolls.prevYear(obj.currentDate);
					privateMethods.setMonthByDate(date,obj);
				});
				obj.nextYear.click(function(){
					var date=tolls.nextYear(obj.currentDate);
					privateMethods.setMonthByDate(date,obj);
				});
				obj.unselectedDays.live("click",function(){
					return false;
				});
				obj.unDays.live("click",function(){
					return false;
				});
				if(o.showTolls&&obj.isInput){
					if(o.showClear) obj.clearBtn.bind("click",function(e){
						var clearFun=function(){
							$this.val("");
							tolls.hide($datepicker);
						};
						if($.isFunction(o.clearHandler)){
							var f=o.clearHandler.call(this,e,$this,$datepicker);
							if(typeof f=="undefined" || f){
								clearFun();
							}
						}else{
							clearFun();
						}
					});
					if(o.showToday) obj.todayBtn.bind("click",function(e){
						var date=new Date(),dateStr=tolls.dateToString(date,o.format);
						var todayFun=function(){
							if(!tolls.isDisabledDate(date)&&!tolls.isDisabledTime(date)){								
								var f=true;
								if($.isFunction(o.beforeSelect)){
									f=o.beforeSelect.call(this,dateStr,date,$this,obj);
								}
								if(typeof f=="undefined"||f){
									privateMethods.selectDate(date,obj,true);
								}								
							}
						}; 
						if($.isFunction(o.todayHandler)){
							var f=o.todayHandler.call(this,e,dateStr,date,$this,obj);
							if(typeof f=="undefined" || f){									
								todayFun();
							}
						}else{
							todayFun();
						}
					});
					if(o.showOk) obj.okBtn.bind("click",function(e){
						if(obj.ableDays.length<1) return false;
						var day=obj.ableDays.last(),dateStr,date;
						obj.ableDays.each(function(){
							if($(this).parent().hasClass("selected-day")){
								day=$(this);
								return;
							}
						});
						date=tolls.getDate(day,obj);
						dateStr=tolls.dateToString(date,o.format);
						var okFun=function(){
							if(!tolls.isDisabledDate(date)&&!tolls.isDisabledTime(date)){
								var f=true;
								if($.isFunction(o.beforeSelect)){
									f=o.beforeSelect.call(this,dateStr,date,$this,obj);
								}
								if(typeof f=="undefined"||f){
									obj.clickDates=new Array();
									obj.clickDates.push(tolls.dateToString(date,"yyyy-mm-dd"));
									//obj.clickDates=privateMethods.unique(obj.clickDates);
									privateMethods.selectDate(date,obj);
								}
							}
						};
						if($.isFunction(o.okHandler)){
							var f=o.okHandler.call(this,e,dateStr,date,$this,obj);
							if(typeof f=="undefined" || f){
								okFun();
							}
						}else{
							okFun();
						}
					});
				}
				obj.ableDays.live("click",function(e){
					var date=tolls.getDate($(this),obj),dateStr=tolls.dateToString(date,o.format),t=$(this);
					var clickFun=function(){
						if(!tolls.isDisabledDate(date)&&!tolls.isDisabledTime(date)){
							var f=true;
							if($.isFunction(o.beforeSelect)){
								f=o.beforeSelect.call(this,dateStr,date,t,obj);
							}
							if(obj.isInput&&(typeof f=="undefined"||f)){
								obj.clickDates=new Array();
								obj.clickDates.push(tolls.dateToString(date,"yyyy-mm-dd"));
								//obj.clickDates=privateMethods.unique(obj.clickDates);
								privateMethods.selectDate(date,obj);
							}
						}
					};
					if($.isFunction(o.beforeClick)){
						var f=o.beforeClick.call(this,e,dateStr,date,t,obj);
						if(typeof f=="undefined" || f){
							clickFun();
						}else{
							return false;
						}
					}else{
						clickFun();
					}
					if($.isFunction(o.click)){
						var r;
						r=o.click.call(this,e,dateStr,date,t,obj);
						if(typeof r=="undefined" || !r){
							return false;
						}else{
							return true;
						}
					}else{
						return false;
					}					
				});
				if($.isFunction(o.dblclick)) obj.ableDays.live("dblclick",function(e){
					var date=tolls.getDate($(this),obj);
					return o.dblclick.call(this,e,tolls.dateToString(date,o.format),date,$(this),obj);
				});
				if($.isFunction(o.mouseover)) obj.ableDays.live("mouseover",function(e){
					var date=tolls.getDate($(this),obj);
					return o.mouseover.call(this,e,tolls.dateToString(date,o.format),date,$(this),obj);
				});
				if($.isFunction(o.mouseout)) obj.ableDays.live("mouseout",function(e){
					var date=tolls.getDate($(this),obj);
					return o.mouseout.call(this,e,tolls.dateToString(date,o.format),date,$(this),obj);
				});
				if($.isFunction(o.event)&&o.eventName) obj.ableDays.live(o.eventName,function(e){
					var date=tolls.getDate($(this),obj);
					return o.event.call(this,e,tolls.dateToString(date,o.format),date,$(this),obj);
				});
			};
			//try{
				init();
				tolls.doms=obj;
				calendars.push(tolls);
				return;
			//}catch(e){}
		});
		return calendars[0];
	};
	
		   
		})(jQuery)
